package org.stars.dao.loader;

import java.io.InputStream;

import org.stars.dao.sqlmapper.SqlBase;
import org.stars.dao.sqlmapper.SqlMapper;
import org.stars.dao.sqlmapper.SqlMapperImpl;


public class XmlSqlMapperLoader extends XmlBaseLoader<SqlMapper, SqlMapperImpl>  {
		
	/**
	 * Load a sqlmapper named "name" from inputStream.
	 * 
	 * @param name
	 * 			name of the sqlMapper
	 * @param inputStream
	 * 			inputStream
	 * @return
	 * 			sqlMapper
	 * @throws Exception
	 */
	public SqlMapper load(String name, InputStream inputStream) throws Exception
	{
		SqlMapper mapper=load(name, inputStream, SqlMapperImpl.class);
		
		for (SqlBase item: mapper.getMap().values())
		{
			item.setSqlMapper(mapper);
		}
		
		return mapper;
	}
	
	/**
	 * Load a sqlMapper from file.
	 * @param fileName
	 * @return
	 * @throws Exception
	 */
	public SqlMapper load(String fileName) throws Exception
	{
		SqlMapper mapper=load(fileName, SqlMapperImpl.class);
		
		for (SqlBase item: mapper.getMap().values())
		{
			item.setSqlMapper(mapper);
		}
		
		return mapper;
	}
}
